package beer.coder.imageviewer.handler;

import beer.coder.imageviewer.ImageViewer;
import javafx.event.EventHandler;
import javafx.scene.input.ScrollEvent;

/**
 * TODO
 *
 * @author amath0312
 * @version 1.0
 * @date 2020-11-01 14:32
 */
public class ImageViewZoomHandler implements EventHandler<ScrollEvent> {

  double step = 0.1;
  protected ImageViewer imageView;

  public ImageViewZoomHandler(ImageViewer imageView) {
    this.imageView = imageView;
  }

  @Override
  public void handle(ScrollEvent event) {
    double delta;
    if (event.getDeltaY() < 0) {
      delta = -step;
    } else {
      delta = step;
    }
    this.imageView.zoom(delta);

    event.consume();
  }
}
